<?php
declare(strict_types = 1);

namespace leruge;

class Events
{
    public static function onConnect($client_id)
    {
        $resData = [
            'type' => 11,
            'client_id' => $client_id
        ];
        \GatewayWorker\Lib\Gateway::sendToClient($client_id, json_encode($resData));
    }

    public static function onMessage($client_id, $data)
    {
        $arr = json_decode($data, true);
        if ($arr && isset($arr['type']) && $arr['type'] == 12 && isset($arr['member_id'])) {
            \GatewayWorker\Lib\Gateway::bindUid((string)$arr['client_id'], (string)$arr['member_id']);
            \GatewayWorker\Lib\Gateway::sendToClient(($client_id), json_encode(['type' => 'bind_success']));
        }
    }

    public static function onClose($client_id)
    {}
}